package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;

public class SeriesCollection extends CollectionBase {
   private Chart b;

   SeriesCollection(Chart chart) {
      this.b = chart;
   }

   Worksheet a() {
      return this.b.getWorksheet();
   }

   WorksheetCollection b() {
      return this.b.j();
   }

   public Series get(int index) {
      return (Series)this.a.get(index);
   }

   public Series getSeriesByOrder(int order) {
      this.c();
      Iterator var2 = this.a.iterator();

      Series var3;
      do {
         if (!var2.hasNext()) {
            return null;
         }

         var3 = (Series)var2.next();
      } while(var3.z() != order);

      return var3;
   }

   void c() {
      ArrayList var1 = new ArrayList();
      Iterator var2 = this.a.iterator();

      while(var2.hasNext()) {
         Series var3 = (Series)var2.next();
         zmb var4 = new zmb(var3);
         com.aspose.cells.b.a.a.ze.a(var1, (Object)var4);
      }

      Collections.sort(var1);

      for(int var5 = 0; var5 < var1.size(); ++var5) {
         zmb var6 = (zmb)var1.get(var5);
         var6.a().e(var5);
      }

   }

   public void removeAt(int index) {
      Series var2 = (Series)this.a.get(index);
      this.a.remove(index);
   }

   void a(int var1, int var2) {
      com.aspose.cells.b.a.a.ze.a(this.a, var1, var2);
   }

   public String getCategoryData() {
      Iterator var1 = this.iterator();

      Series var2;
      do {
         if (!var1.hasNext()) {
            return "";
         }

         var2 = (Series)var1.next();
      } while(var2.getPlotOnSecondAxis());

      return var2.getXValues();
   }

   public void setCategoryData(String value) {
      String var2 = value.trim();
      Iterator var3 = this.iterator();

      while(var3.hasNext()) {
         Series var4 = (Series)var3.next();
         if (!var4.getPlotOnSecondAxis()) {
            var4.setXValues(var2);
         }
      }

   }

   /** @deprecated */
   public String getSecondCatergoryData() {
      return this.getSecondCategoryData();
   }

   /** @deprecated */
   public void setSecondCatergoryData(String value) {
      this.setSecondCategoryData(value);
   }

   public String getSecondCategoryData() {
      Iterator var1 = this.iterator();

      Series var2;
      do {
         if (!var1.hasNext()) {
            return "";
         }

         var2 = (Series)var1.next();
      } while(!var2.getPlotOnSecondAxis());

      return var2.getXValues();
   }

   public void setSecondCategoryData(String value) {
      String var2 = value.trim();
      Iterator var3 = this.iterator();

      while(var3.hasNext()) {
         Series var4 = (Series)var3.next();
         if (var4.getPlotOnSecondAxis()) {
            var4.setXValues(var2);
         }
      }

   }

   private void b(Series var1) {
      switch(this.b.getType()) {
      case 65:
         var1.getBorder().setVisible(false);
         if (this.a.size() == 2) {
            var1.getMarker().setMarkerStyle(4);
            var1.getMarker().a(Color.getBlack());
            var1.getMarker().b(Color.getBlack());
         }
         break;
      case 66:
         var1.getBorder().setVisible(false);
         break;
      case 67:
         var1.getBorder().setVisible(false);
         var1.getMarker().setMarkerStyle(5);
         if (this.a.size() == 0) {
            var1.a(this.b.c.a(0));
            var1.a(3);
         } else if (this.a.size() < 3) {
            var1.a(this.b.c.a(1));
            var1.a(this.a.size() - 1);
         } else if (this.a.size() == 3) {
            var1.a(this.b.c.a(1));
            var1.getMarker().setMarkerStyle(4);
            var1.getMarker().a(Color.getBlack());
            var1.getMarker().b(Color.getBlack());
            var1.a(this.a.size() - 1);
         }
         break;
      case 68:
         if (this.a.size() == 0) {
            var1.a(this.b.c.a(0));
            var1.a(4);
         } else if (this.a.size() < 5) {
            var1.getBorder().setVisible(false);
            var1.getMarker().setMarkerStyle(5);
            var1.a(this.b.c.a(1));
            var1.setGapWidth((short)100);
            var1.a(this.a.size() - 1);
         }
      }

   }

   private void c(Series var1) {
      this.b(var1);
      if (var1.getType() == 13) {
         var1.setHas3DEffect(true);
      }

   }

   private void d(Series var1) {
      this.c(var1);
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
   }

   public void changeSeriesOrder(int sourceIndex, int destIndex) {
      Series var3 = this.get(destIndex);
      Series var4 = this.get(sourceIndex);
      this.a.set(destIndex, var4);
      this.a.set(sourceIndex, var3);
   }

   void b(int var1, int var2) {
      Series var3 = this.get(var1);
      this.a.add(var2, var3);
      this.a.remove(var1 + 1);
   }

   void c(int var1, int var2) {
      Series var3 = this.get(var1);
      this.a.add(var2, var3);
      this.a.remove(var1);
   }

   void a(Series var1) {
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
   }

   public int addR1C1(String area, boolean isVertical) {
      area = zasp.b(area, 0, 0);
      return this.add(area, isVertical);
   }

   public int add(String area, boolean isVertical) {
      return this.a(area, isVertical, false);
   }

   int a(String var1, boolean var2, boolean var3) {
      if (var1 == null) {
         return -1;
      } else {
         var1 = var1.trim();
         zik var5 = zin.a(this.b(), this.a(), var1);
         int var6 = this.getCount();
         Series var4;
         switch(var5.q()) {
         case 1:
         case 6:
            var4 = new Series(this.b(), this, this.getCount());
            var4.setValues(var1);
            var4.d(this.b.getType());
            this.d(var4);
            break;
         case 2:
         case 5:
            var4 = new Series(this.b(), this, this.getCount());
            var4.setValues(var1);
            var4.d(this.b.getType());
            this.d(var4);
            break;
         case 3:
            int var7 = var5.j();
            String var8 = zyn.a(var7, this.b(), 0, (HashMap)null);
            this.a(var2, var8, var5.m(), var5.n(), var5.o(), var5.p(), var3);
            break;
         case 4:
            Range var9 = var5.l();
            if (var9 != null) {
               if (var2) {
                  if (var9.getColumnCount() == 1) {
                     var4 = new Series(this.b(), this, this.getCount());
                     var4.a(var5);
                     var4.d(this.b.getType());
                     this.d(var4);
                     return var6;
                  }
               } else if (var9.getRowCount() == 1) {
                  var4 = new Series(this.b(), this, this.getCount());
                  var4.a(var5);
                  var4.d(this.b.getType());
                  this.d(var4);
                  return var6;
               }

               CellArea var10 = var9.a();
               String var11 = var9.getWorksheet().getName();
               if (!"".equals(var11) && zakq.b(var11)) {
                  var11 = "'" + var11 + "'";
               }

               this.a(var2, var11, var10.StartRow, var10.StartColumn, var10.EndRow, var10.EndColumn, false);
            }
            break;
         default:
            throw new CellsException(6, "Invalid series values");
         }

         if (this.getCount() >= 256) {
            throw new CellsException(10, "The number of series could not exceed 256.");
         } else {
            return var6;
         }
      }
   }

   private void a(boolean var1, String var2, int var3, int var4, int var5, int var6, boolean var7) {
      Worksheet var8 = this.b().get(var2);
      if (!"".equals(var2)) {
         var2 = var2 + "!";
      }

      boolean var9 = false;
      String var10 = "";
      Cells var11;
      Cell var12;
      boolean var13;
      boolean var14;
      int var15;
      Cell var16;
      Cell var17;
      int var18;
      String var19;
      String var20;
      Series var21;
      boolean var22;
      int var23;
      if (var1) {
         if (var8 != null && var7) {
            var11 = var8.getCells();
            var12 = var11.get(var3, var4);
            var13 = false;
            if (var12.getType() == 5 || var12.getType() == 1) {
               var13 = true;
            }

            var14 = false;
            if (var6 - var4 > 1) {
               var14 = true;

               for(var15 = var4 + 1; var15 <= var6; ++var15) {
                  var16 = var11.get(var3, var15);
                  if (var16.getType() != 5 && var16.getType() != 1) {
                     var14 = false;
                     break;
                  }
               }
            }

            var22 = false;
            if (var5 - var3 > 1) {
               var22 = true;

               for(var23 = var3 + 1; var23 <= var5; ++var23) {
                  var17 = var11.get(var23, var4);
                  if (var17.getType() != 5 && var17.getType() != 1) {
                     var22 = false;
                     break;
                  }
               }
            }

            if (var14 && var22) {
               var9 = true;
               var10 = var2 + CellsHelper.cellIndexToName(var3 + 1, var4) + ":" + CellsHelper.cellIndexToName(var5, var4);
               ++var3;
               ++var4;
            } else if (!var14 && var22 && var13) {
               var10 = var2 + CellsHelper.cellIndexToName(var3, var4) + ":" + CellsHelper.cellIndexToName(var5, var4);
               ++var4;
            } else if (var14 && !var22 && var13) {
               var9 = true;
               ++var3;
            }

            if (var13 && var3 == var5 && var4 != var6) {
               var10 = var2 + CellsHelper.cellIndexToName(var3, var4) + ":" + CellsHelper.cellIndexToName(var3, var4);
               ++var4;
            } else if (var13 && var3 != var5 && var4 == var6) {
               var9 = true;
               ++var3;
            }
         }

         for(var18 = var4; var18 <= var6; ++var18) {
            var19 = CellsHelper.cellIndexToName(var3, var18);
            var20 = CellsHelper.cellIndexToName(var5, var18);
            var21 = new Series(this.b(), this, this.getCount());
            var21.setValues(var2 + var19 + ":" + var20);
            if (var9) {
               var21.setName("=" + var2 + CellsHelper.cellIndexToName(var3 - 1, var18));
            }

            if (!"".equals(var10)) {
               var21.setXValues(var10);
            }

            var21.d(this.b.getType());
            if (this.getCount() < 65535) {
               this.d(var21);
            }
         }
      } else {
         if (var8 != null && var7) {
            var11 = var8.getCells();
            var12 = var11.get(var3, var4);
            var13 = false;
            if (var12.getType() == 5 || var12.getType() == 1) {
               var13 = true;
            }

            var14 = false;
            if (var6 - var4 > 1) {
               var14 = true;

               for(var15 = var4 + 1; var15 <= var6; ++var15) {
                  var16 = var11.get(var3, var15);
                  if (var16.getType() != 5 && var16.getType() != 1) {
                     var14 = false;
                     break;
                  }
               }
            }

            var22 = false;
            if (var5 - var3 > 1) {
               var22 = true;

               for(var23 = var3 + 1; var23 <= var5; ++var23) {
                  var17 = var11.get(var23, var4);
                  if (var17.getType() != 5 && var17.getType() != 1) {
                     var22 = false;
                     break;
                  }
               }
            }

            if (var14 && var22) {
               var9 = true;
               var10 = var2 + CellsHelper.cellIndexToName(var3, var4 + 1) + ":" + CellsHelper.cellIndexToName(var3, var6);
               ++var3;
               ++var4;
            } else if (!var14 && var22 && var13) {
               var9 = true;
               ++var4;
            } else if (var14 && !var22 && var13) {
               var10 = var2 + CellsHelper.cellIndexToName(var3, var4) + ":" + CellsHelper.cellIndexToName(var3, var6);
               ++var3;
            }

            if (var13 && var3 == var5 && var4 != var6) {
               var9 = true;
               ++var4;
            } else if (var13 && var3 != var5 && var4 == var6) {
               var10 = var2 + CellsHelper.cellIndexToName(var3, var4) + ":" + CellsHelper.cellIndexToName(var3, var4);
               ++var3;
            }
         }

         for(var18 = var3; var18 <= var5; ++var18) {
            var19 = CellsHelper.cellIndexToName(var18, var4);
            var20 = CellsHelper.cellIndexToName(var18, var6);
            var21 = new Series(this.b(), this, this.getCount());
            var21.setValues(var2 + var19 + ":" + var20);
            if (var9) {
               var21.setName("=" + var2 + CellsHelper.cellIndexToName(var18, var4 - 1));
            }

            if (!"".equals(var10)) {
               var21.setXValues(var10);
            }

            var21.d(this.b.getType());
            if (this.getCount() < 65535) {
               this.d(var21);
            }
         }
      }

   }

   void a(SeriesCollection var1, CopyOptions var2) {
      for(int var3 = 0; var3 < var1.a.size(); ++var3) {
         Series var4 = (Series)var1.a.get(var3);
         Series var5 = new Series(this.b(), this, this.getCount());
         var5.a(var4, var2);
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)var5);
      }

   }

   public boolean isColorVaried() {
      return this.b.c.a(0).y();
   }

   public void setColorVaried(boolean value) {
      switch(this.b.getType()) {
      case 44:
      case 45:
      case 46:
      case 47:
      case 48:
      case 49:
         this.b.c.a(0).j(value);
         break;
      default:
         if (this.getCount() == 1) {
            this.b.c.a(0).j(value);
         }
      }

   }

   Chart d() {
      return this.b;
   }

   int a(boolean var1) {
      int var2 = 0;
      Iterator var3 = this.iterator();

      while(var3.hasNext()) {
         Series var4 = (Series)var3.next();
         if (var4.s().m() == var1) {
            ++var2;
         }
      }

      return var2;
   }

   void a(ziz var1, DataLabels var2) {
      CopyOptions var3 = new CopyOptions(true);
      Iterator var4 = this.iterator();

      while(var4.hasNext()) {
         Series var5 = (Series)var4.next();
         if (var5.s() == var1 && var5.p() == null) {
            var5.getDataLabels().a(var2, var3);
         }
      }

   }
}
